package com.study.design.pattern.pattern.creational.singleton.container;

import cn.hutool.core.util.StrUtil;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: gongsl
 * @Date: 2025-02-23 15:58
 * @description:
 */
public class ContainerSingleton {
    private static Map<String, Object> singletonMap = new HashMap<>();

    public static void putInstance(String key, Object instance) {
        if (StrUtil.isNotBlank(key) && instance != null) {
            if (!singletonMap.containsKey(key)) {
                singletonMap.put(key, instance);
            }
        }
    }

    public static Object getInstance(String key) {
        return singletonMap.get(key);
    }
}
